import requests from './axios'
import qs from 'qs' //处理post请求
export const reqGoodsUpload=(formData)=>requests.post(`goods_upload.php`,formData)
export const reqUploadIcon=(formData)=>requests.post(`user_icon.php`,formData)
// commonmall组件，添加到购物车
export const reqAddCar=(id,token) => {
    // let token = JSON.parse(localStorage.getItem('key')).token
    let obj = qs.stringify({token,id});
    return requests.post('car_add.php',obj)
}
export const reqLogoutAmount=(token)=>requests.get(`logout_amount.php?token=${token}`)
// nav组件，获取个人信息
export const reqUserInfo=(token)=>{
    let obj = qs.stringify({token})
    return requests.post('user_info.php',obj)
}
// car组件，购物车列表
export const reqCarList=(token)=>{
    let obj = qs.stringify({token})
    return requests.post('car_list.php',obj)
}
// 购物车中删除单个商品
export const reqCarDelete=(id)=>requests.get(`car_delete.php?id=${id}`)
// 删除选中得商品
export const reqCarDeleteSeletced=(arr)=>requests({url:'car_delete_selected.php',methods:'get',params:{arr}})
// 提交订单接口，settlement组件
export const reqOrderSubmit=(token,id,car_id,num,isCarFrom)=>{
    let obj = qs.stringify({token,id,car_id,num,isCarFrom});
    return requests.post('order_submit.php',obj)
}
export const reqAdminOrder=()=>requests.get("admin_order.php")
// 订单列表
export const reqOrderList=(token)=>requests.get(`order_list.php?token=${token}`)
export const reqDeleteOrder=(id)=>requests.get(`order_delete.php?id=${id}`)
export const reqDeleteSonOrder=(id)=>requests.get(`order_son_delete.php?id=${id}`)
// 地址管理
export const reqAddressList=(token)=>requests.get(`address_list.php?token=${token}`)
export const reqAddressPerson=(token)=>requests.get(`address_person.php?token=${token}`)
export const reqAddressAdd=(token,user,tel,address)=>{
    let obj = qs.stringify({token,user,tel,address})
    return requests.post('address_add.php',obj)
}
export const reqAddressDefault=(id)=>requests.get(`address_default.php?id=${id}`)
export const reqAddressDelete=(id)=>requests.get(`address_delete.php?id=${id}`)
// 注册
export const reqUserRegister=(user,pass)=>{
    let obj = qs.stringify({user,pass});
    return requests.post('user_register.php',obj)
}
// 登录
export const reqUserLogin=(user,pass)=>{
    let obj = qs.stringify({user,pass});
    return requests.post('user_login.php',obj)
}
// 获取商品类别的类型
export const reqCategoryType=()=>requests.get('category_type.php')
// 点击分类按钮进行商品分类
export const reqCategory=(mark,search)=>{
    return requests.get('category.php',{
        params:{type:mark.type,price:mark.price,time:mark.time,search:search}
    })
}
// 主要热门排行
export const reqSortNew=(mark)=>requests.get(`index_sort_new.php?mark=${mark}`)
export const reqSortPrice=(mark)=>requests.get(`index_sort_price.php?mark=${mark}`)
// 随机商品,轮播图
export const reqRandomGoods = () => requests.get('goods_random.php');
export const reqGoodsType=()=>requests.get('goods_type.php')
//  单个商品类型
export const reqTypeGoods=(type)=>requests.get(`goods_type_list.php?type=${type}`)
// mall组件，所有商品
export const reqGoodsAll = () => requests.get('goods_all.php');
// index组件，为你推荐
export const reqGoodsRecommend = () => requests.get('goods_recommend.php');
// nav组件，搜索框
export const reqGoodsSearch = (search) => {
    if (search === '') {
        return
    }else{
        let obj = qs.stringify({search});
        return requests.post('goods_search.php',obj);
    }
};
// 后台管理系统，
// 商品管理
export const reqGoodsAdmin = () => requests.get('admin_goods.php');
export const reqUserAdmin = () => requests.get('admin_user.php');
export const reqAdminCensus = () => requests.get('admin_census.php');
export const reqAdminEcharts1 = () => requests.get('admin_echarts1.php');
export const reqAdminEcharts2 = () => requests.get('admin_echarts2.php');
export const reqAdminEcharts3 = () => requests.get('admin_echarts3.php');
export const reqAdminEcharts4 = () => requests.get('admin_echarts4.php');
